<?php
###############   COPYLEFT GPLv3 LICENSE   ###############
##
## JFX Version 0.2.9
## Website Management Software
## www.jfxcms.com
##
## Copyright 2009 GPLv3 - http://www.opensource.org/licenses/gpl-3.0.html
##
## Anthony Gallon
## oi_antz@hotmail.com
##
## Permission is hereby granted to any person having a copy of this software
## to freely use and modify as required so long as the copyright notices
## and branding remain intact.
##
## Full license details available at http://www.jfxcms.com/license
##
###############   COPYLEFT GPLv3 LICENSE   ###############

$VIEW->template = 'admin-thickbox.tpl';


$CONFIG->debug = true;


$blockid = get('blockId');
$pageid = $pageId;

$blockids = explode('-', $blockid);

if(count($blockids)==2){
    // is a page block
    JFX::addError($this->lang('cannot_update_styles_on_page_block'));
    return;
}

$block = JFX_Block::getBlockById($blockid, $pageId);
if($block->id === ''){
    die($this->lang('unsaved_block'));
}

$extraClassnames = array('selected'=>array(), 'options'=>array(), 'block'=>$block);
JFX::hook('JFX_Core.styleblockClassnames', $extraClassnames);


if(Antz_IntelliForm::submitted('update-block-style')){
	$extraClassnamesArray = post('extraClassnames');
	if(is_array($extraClassnamesArray)){
		foreach($extraClassnamesArray as $k=>$classname){
			$hookParams = array('classname'=>$classname, 'block_id'=>$blockid);
			JFX::hook('JFX_Core.styleblockAddClassname', $hookParams);
		}
	}
	if(!is_array($extraClassnamesArray)){
		$extraClassnamesArray = array();
	}
	foreach($extraClassnames['selected'] as $k=>$classname){
		if(!in_array($classname, $extraClassnamesArray)){
			// remove this class
			$hookParams = array('classname'=>$classname, 'block_id'=>$blockid);
			JFX::hook('JFX_Core.styleblockDeleteClassname', $hookParams);
		}
	}

	
	


    $block->setClassName(post('class'));
    $block->setTemplate(post('template', '', 5000));
    $block->setStyle(post('style', '', 5000));
    $block->details['is_droppable'] = (int) post('droppable', 0);
    $block->save();
    JFX::addSuccess($this->lang('styles_updated'));
}







$extraClassnames = array('selected'=>array(), 'options'=>array(), 'block'=>$block);
JFX::hook('JFX_Core.styleblockClassnames', $extraClassnames);

$formFields = array(
    array(
        'type' => 'text',
        'name' => 'class',
        'value' => post('class', $block->getClassName()),
        'label' => $this->lang('class_names')
    ));

if(count($extraClassnames['options'])>0){

	$formFields[] = array(
		'type' => 'select',
		'size' => 4,
		'name' => 'extraClassnames[]',
		'value' => $extraClassnames['selected'],
		'options' => $extraClassnames['options'],
		'label' => $this->lang('extra_classnames'),
		'multiple' => true
	);

}




$formFields[] =
    array(
        'type' => 'checkbox',
        'name' => 'droppable',
        'value' => 1,
        'label' => $this->lang('is_droppable'),
        'checked' => (post('droppable', $block->getDetails('is_droppable')))
    );
$formFields[] =
    array(
        'type' => 'code',
        'name' => 'template',
		'class' => 'html',
		'id' => 'codetemplate',
        'value' => post('template', $block->getTemplate()),
        'label' => $this->lang('template')
    );
$formFields[] =
    array(
        'type' => 'code',
        'name' => 'style',
		'class' => 'css',
		'id' => 'codestyle',
        'value' => post('style', $block->getDetails('block_style')),
        'label' => $this->lang('css_style')
    );
$formFields[] =
    array(
        'type' => 'submit',
        'name' => 'submitBtn',
        'value' => $this->lang('update_style_submit'),
        'label' => '&nbsp;'
    );


echo JFX::makeRapidForm($formFields, $this->lang('style_block_legend'), 'update-block-style');


echo '<script type="text/javascript" language="JavaScript">
setTimeout(CodePress.run, 1100);
</script>';



